/* eslint-disable react/prop-types */
import { hasToken } from '@/utils/storage'
import React from 'react'
import { Route, Redirect } from 'react-router-dom'
// 我们需要解构所有的属性，除了component属性
export default function PrivateRoute ({ component, path }) {
  const Component = component
  return (
    <Route
      path={path}
      render={() => {
        if (hasToken()) {
          return <Component />
        } else {
          return <Redirect to="/login" />
        }
      }}
    />
  )
}
